﻿<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="FT.Architecture.Example.Core.Entities.Humans" assembly="FT.Architecture.Example.Core">
  <class name="FT.Architecture.Example.Core.Entities.Humans.IHuman" table="human">
    <cache usage ="nonstrict-read-write"/>

    <id name="Id" column="ID_Human" unsaved-value="0">
      <generator class="hilo">
        <param name="table">aa_hi_lo</param>
        <param name="column">next_value</param>
        <param name="max_lo">99</param>
      </generator>
    </id>

    <discriminator type="string" column="type"></discriminator>

    <subclass name="HumanBase">

      <property name="Name" />
      <property name="DateBorn" />
      <property name="Telephone" column="PhoneNumber" />
      <property name="CV">
        <column name="CV" sql-type="NTEXT"></column>
      </property>

      <many-to-one name="MarriedTo" column="ID_MarriedTo" access="field.camelcase" class="FT.Architecture.Example.Core.Entities.Humans.IHuman" foreign-key="FK_Human_MarriedTo"></many-to-one>
      <many-to-one name="Father"    column="ID_Father"    access="field.camelcase" class="FT.Architecture.Example.Core.Entities.Humans.Man" foreign-key="FK_Human_Father"></many-to-one>
      <many-to-one name="Mother"    column="ID_Mother"    access="field.camelcase" class="FT.Architecture.Example.Core.Entities.Humans.Woman" foreign-key="FK_Human_Mother"></many-to-one>

      <set name="Pets" table="human_pet" access="field.camelcase">
        <key column="ID_Human"></key>
        <many-to-many class="FT.Architecture.Example.Core.Entities.Pets.IPet" column="ID_Pet"></many-to-many>
      </set>

      <set name="BorrowedPets" access="field.camelcase" cascade="all-delete-orphan" inverse="true">
        <key column="ID_BorrowedBy"></key>
        <one-to-many class="FT.Architecture.Example.Core.Entities.Pets.IPet"></one-to-many>
      </set>

      <set name="Subscriptions" access="field.camelcase">
        <key column="Owner"></key>
        <one-to-many class="FT.Architecture.Example.Core.Entities.Subscriptions.Subscription" />
      </set>

      <set name="Cars" access="field.camelcase">
        <key column="ID_Owner"></key>
        <one-to-many class="FT.Architecture.Example.Core.Entities.Cars.ICar" />
      </set>

      <subclass name="Man" discriminator-value="boy">
        <subclass name="Superman" discriminator-value="superman"></subclass>
      </subclass>

      <subclass name="Woman" discriminator-value="girl">
        <property name="LengthOfHairs" />
        
        <set name="Children" access="field.camelcase" inverse="true">
          <key column="ID_Mother"></key>
          <one-to-many class="FT.Architecture.Example.Core.Entities.Humans.IHuman" />
        </set>
      </subclass>

    </subclass>
    
    

  </class>
</hibernate-mapping>